<?php

namespace app\common\model\tysj;

class ProductSpecs extends CUBase {
    protected $hidden = ['is_lock'];
	protected $privacyFields = ['createtime', 'updatetime', 'inventory_warning', 'crowdid'];
    protected $statusKey = false;

    protected static function init()
    {
        parent::init();

        self::beforeInsert(function ($data) {
            if(!isset($data['weight']) || $data['weight'] === null) {
                $data['weight'] = '';
            }
            return $data;
        });

        self::beforeUpdate(function ($data) {
            if(!isset($data['weight']) || $data['weight'] === null) {
                $data['weight'] = '';
            }
            return $data;
        });
    }

	public function delAll($id) {
		try {
            $this->startTrans();
            loadModel('tysj\\ProductSpecsNexus')->where(['psid' => $id])->delete();
            $this->where(['id' => $id])->delete();
            $this->commit();
        } catch (\Exception $e) {
            $this->rollback();
            throw $e;
        }
	}
}